const { Sequelize, DataTypes } = require('sequelize');
const sequelize = require('../config/db');

const OrderItem = sequelize.define('OrderItem', {
  id: {
    type: DataTypes.INTEGER,
    primaryKey: true,
    autoIncrement: true
  },
  order_id: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  dish_id: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  dish_name: {
    type: DataTypes.STRING(255),
    allowNull: false
  },
  dish_image: {
    type: DataTypes.STRING(500)
  },
  original_price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false
  },
  actual_price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false
  },
  quantity: {
    type: DataTypes.INTEGER,
    allowNull: false
  },
  total_price: {
    type: DataTypes.DECIMAL(10, 2),
    allowNull: false
  },
  category_id: {
    type: DataTypes.INTEGER
  },
  category_name: {
    type: DataTypes.STRING(100)
  },
  specifications: {
    type: DataTypes.JSON
  }
}, {
  tableName: 'order_items',
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: false
});

module.exports = OrderItem;